<!--

-->
<template>
  <i v-bind="$attrs" v-on="$listeners" v-show="visible" :class="isInterval()?'el-icon-alarm-clock':'el-icon-watch'" style="font-size: 30px; color: red;">{{isInterval()?'n':1}}</i>
</template>

<script>
export default {
  name: 'mc-timer',
  data () {
    return {
      visible:window.iframeUi,
      intervalTimer:null
    }
  },
  props:{
    //setTimeout,setInterval
    'mcType' : {type:String,default:"setTimeout"},
    //
    'mcMillionSeconds' : {type:Number,default:5000},
  },
  watch:{

  },
  mounted () {
    var _t = this;
    switch (this.mcType){
      case 'setTimeout':
        setTimeout(function () {
          _t.$emit("mc-execute")
        },this.mcMillionSeconds)
        break;
      case 'setInterval':
        this.intervalTimer = setInterval(function () {
          _t.$emit("mc-execute")
        },this.mcMillionSeconds)
        //布局器会主动清理此定时任务 避免重复注册
        if(window.iframeUi){
          window._mcCacheIntervals.push(this.intervalTimer)
        }
        break;
    }
  },
  methods:{
    isInterval(){
      return this.mcType=='setInterval'
    }
  },
  beforeDestroy () {
    // 销毁定时任务
    clearInterval(this.intervalTimer)
  },
}
</script>

<style lang="scss">

</style>
